class News extends React.Component{
	state={news_arr:[]}
	componentDidUpdate(_,preState,snapshotValue){
		this.refs.list.scrollTop+=this.refs.list.scrollHeight-snapshotValue;
	}
	componentDidMount(){

		setInterval(()=>{
			const {news_arr}=this.state;
			const news='新闻'+(news_arr.length+1);
			this.setState({
				news_arr:[news,...news_arr]
			})
		},1000)
	}
	getSnapshotBeforeUpdate(){
		console.log(this.refs.list.scrollHeight)
		return this.refs.list.scrollHeight
	}
	 render(){
	 	return (
	 		<div className="list" ref="list">
				{
					 this.state.news_arr.map((n,index)=>{
						return <div className="news" key={index}>{n}</div>
				  })
				}
			</div>
		)
	 }
}
ReactDOM.render(<News></News>,document.getElementById("test"));
